package com.zwj.controller;


import com.zwj.bo.AddHomeworkBo;
import com.zwj.bo.SelectHomeworkInfoBo;
import com.zwj.bo.WorkApproval;
import com.zwj.entity.UserEntity;
import com.zwj.service.WorkInfoService;
import com.zwj.utils.TokenUtils;
import com.zwj.vo.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 作业信息表 前端控制器
 * </p>
 *
 * @author zwj
 * @since 2021-07-21
 */
@RestController
@RequestMapping("/work-info-entity")
public class WorkInfoController {
    private final WorkInfoService workInfoService;
    public WorkInfoController(WorkInfoService workInfoService){
        this.workInfoService=workInfoService;
    }

    @PostMapping("/addHomework")
    public Result addHomework(@RequestBody AddHomeworkBo addHomeworkBo, HttpServletRequest request){
        UserEntity user = TokenUtils.getUser(request);
        return  workInfoService.addHomework(addHomeworkBo,user);
    }

    @GetMapping("/selectHomeWorkById/{workId}")
    Result selectHomeWorkById(@PathVariable Long workId){
        return workInfoService.selectHomeWorkById(workId);
    }

    @PostMapping("/selectHomeworkInfo")
    Result selectHomeworkInfo(@RequestBody SelectHomeworkInfoBo selectHomeworkInfoBo){
        return workInfoService.selectHomeworkInfo(selectHomeworkInfoBo);
    }

    @DeleteMapping("/deleteHomework/{workId}")
    Result deleteHomework(@PathVariable Long workId){
        return workInfoService.deleteHomework(workId);
    }

    @ApiOperation(value = "查看学生作业", notes = "查看学生作业")
    @GetMapping("/selectHomeworkStudent_t")
    public Result selectHomeworkStudent(Long submitId,HttpServletRequest request) {
        UserEntity userEntity = TokenUtils.getUser(request);
        return workInfoService.selectHomeworkStudent(submitId,userEntity);
    }

    @ApiOperation(value = "提交作业批复", notes = "提交作业批复")
    @PostMapping("/submitWorkApproval_t")
    public Result submitWorkApproval(@RequestBody WorkApproval workApproval, HttpServletRequest request) {
        UserEntity userEntity = TokenUtils.getUser(request);
        return workInfoService.submitWorkApproval(workApproval,userEntity);
    }

    @ApiOperation(value = "保存作业批复", notes = "保存作业批复")
    @PostMapping("/saveWorkApproval_t")
    public Result saveWorkApproval(@RequestBody WorkApproval workApproval,HttpServletRequest request) {
        UserEntity userEntity = TokenUtils.getUser(request);
        return workInfoService.saveWorkApproval(workApproval,userEntity);
    }




}

